import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/routes/account/controller/xindong_login_ctr.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_button.dart';
import 'package:xindong/widgets/xindong_number_text_field.dart';

class XinDongPasswordLoginYeMian extends StatefulWidget {
  const XinDongPasswordLoginYeMian({super.key});

  @override
  State<XinDongPasswordLoginYeMian> createState() => _XinDongPasswordLoginYeMianState();
}

class _XinDongPasswordLoginYeMianState extends State<XinDongPasswordLoginYeMian> {
  final _accountController = TextEditingController();
  final _passwordController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar("密码登录"),
      body: GestureDetector(
        onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
        child: Center(
          child: Container(
            alignment: Alignment.topCenter,
            padding: const EdgeInsets.all(20),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(
                  height: 48,
                  child: XinDongNumberTextField(
                    hintText: '请输入账号',
                    controller: _accountController,
                    keyboardType: TextInputType.phone,
                    inputFormatters: [FilteringTextInputFormatter.digitsOnly, LengthLimitingTextInputFormatter(11)],
                  ),
                ),
                const SizedBox(height: 16),
                SizedBox(
                  height: 48,
                  child: XinDongNumberTextField(
                    hintText: '请输入密码',
                    controller: _passwordController,
                    keyboardType: TextInputType.emailAddress,
                    inputFormatters: [LengthLimitingTextInputFormatter(20)],
                  ),
                ),
                const SizedBox(height: 20),
                SizedBox(
                  height: kButtonHeight,
                  child: XinDongCommonButton(
                    "立即登录",
                    onTap: () {
                      XinDongLoginCtr.to.requestLoginWithPassword(
                        account: _accountController.text,
                        password: _passwordController.text,
                      );
                    },
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
